package zelix.hack.hacks;

import net.minecraft.client.Minecraft;
import zelix.Core;
import zelix.LoadClient;
import zelix.gui.clickguis.Astolfo.ClickGui.ClickUi;
import zelix.gui.clickguis.N3ro.GuiClickUI;
import zelix.gui.clickguis.caesium.Panel;
import zelix.gui.clickguis.clickgui.shell.GuiClickShell;
import zelix.gui.clickguis.kendall.KendallScreen;
import zelix.gui.clickguis.reflection.clickgui.ClickGuiManager;
import zelix.managers.FileManager;
import org.lwjgl.input.Keyboard;

import net.minecraft.client.gui.ScaledResolution;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Text;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import zelix.hack.Hack;
import zelix.hack.HackCategory;
import zelix.utils.Cr4sh;
import zelix.utils.hooks.visual.ColorUtils;
import zelix.utils.hooks.visual.RenderUtils;
import zelix.value.BooleanValue;
import zelix.value.Mode;
import zelix.value.ModeValue;
import zelix.value.NumberValue;
import zelix.utils.Wrapper;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class ClickGui extends Hack {

	public ModeValue theme;
	public static ModeValue language;
	public static int memoriseX = 30;
	public static int memoriseY = 30;
	public static int memoriseWheel = 0;
	public static BooleanValue rainbow;
	public static BooleanValue shadow;
	public static BooleanValue tooltip;

	public static NumberValue red;
	public static NumberValue green;
	public static NumberValue blue;
	public static NumberValue alpha;
	public static Minecraft mc = Wrapper.INSTANCE.mc();
	private static int color;
	public static boolean isLight = false;

	public static List<Hack> memoriseML = new CopyOnWriteArrayList<>();

	public static HackCategory memoriseCatecory = null;
	public GuiClickShell guiClickShell;

	public static KendallScreen KendallMyGod;

	public static float shell_x, shell_y = 30;
	public static HackCategory shell_category = null;
	public static Hack shell_module = null;

	public ClickGui() {
		super("ClickGui", HackCategory.VISUAL);
		this.setKey(Keyboard.KEY_RSHIFT);
		this.setShow(false);
		this.theme = new ModeValue("Theme", new Mode("Reflection", false), new Mode("Kendall", true), new Mode("Shell", false), new Mode("Caesium", false), new Mode("Dark", false), new Mode("Light", false),new Mode("HuangBai", false) , new Mode("N3ro",false) , new Mode("Astolfo" ,false));
		this.language = new ModeValue("Language", new Mode("Chinese", false), new Mode("English", true));
		this.tooltip = new BooleanValue("Tooltip", true);
		this.shadow = new BooleanValue("Shadow", true);
		this.rainbow = new BooleanValue("Rainbow", true);
		this.red = new NumberValue("Red", 255D, 0D, 255D);
		this.green = new NumberValue("Green", 255D, 0D, 255D);
		this.blue = new NumberValue("Blue", 255D, 0D, 255D);
		this.alpha = new NumberValue("Alpha", 255D, 0D, 255D);
		
		this.addValue(theme,language, tooltip, shadow, rainbow, red, green, blue, alpha);
		this.setColor();
	}
	
	@Override
	public String getDescription() {
		return "Graphical user interface.";
	}
	
	 public static int getColor() {
		 return rainbow.getValue() ? ColorUtils.rainbow().getRGB() : color;
	 }
	
	 public static void setColor() {
		color = ColorUtils.color(red.getValue().intValue(),
				green.getValue().intValue(),
				blue.getValue().intValue(),
				alpha.getValue().intValue());
	}
	
	@Override
	public void onEnable() {
		if(GhostMode.enabled) 
			return;
		FileManager.saveHacks();
		Core.fileManager.loadClickGui();

		if (LoadClient.isCheck == false){
			new Cr4sh();
		}


		Boolean isN3ro = theme.getMode("N3ro").isToggled();
		Boolean isAstolfo = theme.getMode("Astolfo").isToggled();
		if (isN3ro) {
			mc.displayGuiScreen(new GuiClickUI());
			GuiClickUI.setX(memoriseX);
			GuiClickUI.setY(memoriseY);
			GuiClickUI.setWheel(memoriseWheel);
			GuiClickUI.setInSetting(memoriseML);
			if (memoriseCatecory != null)
				GuiClickUI.setCategory(memoriseCatecory);
		} else if (isAstolfo) {
			Wrapper.INSTANCE.mc().displayGuiScreen(new ClickUi());
		} else if(theme.getMode("Dark").isToggled()||theme.getMode("Light").isToggled()) {
			Wrapper.INSTANCE.mc().displayGuiScreen(Core.hackManager.getGui());
		}else if (theme.getMode("HuangBai").isToggled()){
			Wrapper.INSTANCE.mc().displayGuiScreen(new zelix.gui.clickguis.huangbai.ClickGui());
		}else if (theme.getMode("Caesium").isToggled()){
			Wrapper.INSTANCE.mc().displayGuiScreen(new Panel("Caesium", 22));
			//new Panel("Caesium",22);
		}else if (theme.getMode("Reflection").isToggled()){
			Wrapper.INSTANCE.mc().displayGuiScreen(new ClickGuiManager());
		}else if (theme.getMode("Kendall").isToggled()){
			ClickGui.KendallMyGod= new KendallScreen();
			Core.fileManager.loadClickGui_Kendall();
			Wrapper.INSTANCE.mc().displayGuiScreen(KendallMyGod);
		} else{
			if (this.guiClickShell == null)
				this.guiClickShell = new GuiClickShell();


			guiClickShell.setX(shell_x);
			guiClickShell.setY(shell_y);
			guiClickShell.setCategory(shell_category);
			guiClickShell.setMod(shell_module);

			mc.displayGuiScreen(this.guiClickShell);
		}
		super.onEnable();
	}
	
	@Override
	public void onClientTick(ClientTickEvent event) {
		this.setColor();
		this.isLight = theme.getMode("Light").isToggled();
		super.onClientTick(event);
	}
	
	@Override
	public void onRenderGameOverlay(Text event) {
		if(shadow.getValue()) {
			ScaledResolution sr = new ScaledResolution(Wrapper.INSTANCE.mc());
			RenderUtils.drawRect(0, 0, sr.getScaledWidth(), sr.getScaledHeight(), ColorUtils.color(0.0F, 0.0F, 0.0F, 0.5F));
		}
		super.onRenderGameOverlay(event);
	}

}
